package android_serialport_api.bean;

import java.text.SimpleDateFormat;
import java.util.Date;

public class ComBean {
    public byte[] bRec = null;
    public String sRecTime = "";
    public String sComPort = "";
    public int size;

    public ComBean(String sPort, byte[] buffer, int size) {
        this.sComPort = sPort;
        this.size = size;
        this.bRec = new byte[size];

        for (int i = 0; i < size; ++i) {
            this.bRec[i] = buffer[i];
        }

        SimpleDateFormat sDateFormat = new SimpleDateFormat("hh:mm:ss");
        this.sRecTime = sDateFormat.format(new Date());
    }

    public ComBean(String sPort, byte[] buffer) {
        this.sComPort = sPort;
        this.size = buffer.length;
        this.bRec = buffer;
        SimpleDateFormat sDateFormat = new SimpleDateFormat("hh:mm:ss");
        this.sRecTime = sDateFormat.format(new Date());
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("ComBean{");
        sb.append("bRec(String)=");
        if (bRec == null) {
            sb.append("null");
        } else {
            sb.append('[');
//            for (int i = 0; i < bRec.length; ++i) {
//                sb.append(i == 0 ? "" : ", ").append(bRec[i]);
//            }
            sb.append(']');
            sb.append(new String(bRec));
        }
        sb.append(", sRecTime='").append(sRecTime).append('\'');
        sb.append(", sComPort='").append(sComPort).append('\'');
        sb.append(", size=").append(size);
        sb.append('}');
        return sb.toString();
    }
}